package com.sinopec.android;



import com.sinopec.android.bean.ResultData;
import com.sinopec.android.bean.ThreadCallBack;
import com.sinopec.android.constant.Constants;
import com.sinopec.android.service.NotificationService;
import com.sinopec.android.util.ExitUtil;
import com.sinopec.android.util.LogUtil;
import com.sinopec.android.util.SharePreferencesUtil;
import com.sinopec.android.util.StringUtil;

import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;


/**
* @ClassName: HomeActivity
* @Description: TODO(主页面)
* @author liuwei
* @date 2012-3-26 下午05:44:56
* 
*/
public class HomeActivity extends BaseActivity implements OnClickListener,ThreadCallBack {
	private String username = "";
	private TextView user_name_text_view ,home_notice_unread_num,home_document_management_unread_num,home_business_trip_unread_num;
	private LinearLayout home_notice_btn,home_document_management_btn,home_business_trip_btn;
	private Button home_todo_btn,home_online_addressbook_btn,home_conference_management_btn,home_leadership_agenda_btn,
	home_mydocuments_btn,home_integrated_query_btn,home_mymailbox_btn;
	private TextView logout;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.home_view);
//		new Thread(
//		 new Runnable() {
//			
//			@Override
//			public void run() {
//				// TODO Auto-generated method stub
//				LogUtil.printInfo("----------调用service");
//				 Intent notification = new Intent(HomeActivity.this, NotificationService.class);  
//				 HomeActivity.this.startService(notification);
//			}
//		}	
//		).start();
	}

	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
		LogUtil.printInfo("-----------onStart");
		//判断是否已登录
		username = SharePreferencesUtil.getLoginUserName(this);
		if(StringUtil.isEmpty(username)){
			//未登录
			Intent intent = new Intent();
			intent.setClass(this, LoginActivity.class);
			startActivity(intent);
			finish();
		}else{
			initView();
		
		}
		
	}
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		LogUtil.printInfo("-----------onResume");
		//显示未读数量
		if(Constants.annouceToDo>0){
			home_notice_unread_num.setText(Constants.annouceToDo+"");
		}
		if(Constants.documentToDo>0){
			home_document_management_unread_num.setText(Constants.documentToDo+"");
		}
		if(Constants.travelToDo>0){
			home_business_trip_unread_num.setText(Constants.travelToDo+"");
		}
	}
	
	void  initView(){
		//用户名
		user_name_text_view = (TextView) findViewById(R.id.user_name_text_view);
		user_name_text_view.setText(username);
		//注销
		logout = (TextView) findViewById(R.id.logout_tet_view);
		logout.setOnClickListener(this);
		//角标
		home_notice_unread_num =  (TextView) findViewById(R.id.home_notice_unread_num);
		home_document_management_unread_num = (TextView) findViewById(R.id.home_document_management_unread_num);
		home_business_trip_unread_num = (TextView) findViewById(R.id.home_business_trip_unread_num);
		//模块按钮
		home_todo_btn = (Button) findViewById(R.id.home_todo_btn);
		home_document_management_btn = (LinearLayout) findViewById(R.id.home_document_management_btn);
		home_notice_btn = (LinearLayout) findViewById(R.id.home_notice_btn);
		home_online_addressbook_btn = (Button) findViewById(R.id.home_online_addressbook_btn);
		home_business_trip_btn =  (LinearLayout) findViewById(R.id.home_business_trip_btn);
		home_conference_management_btn = (Button) findViewById(R.id.home_conference_management_btn);
		home_leadership_agenda_btn = (Button) findViewById(R.id.home_leadership_agenda_btn);
		home_mydocuments_btn = (Button) findViewById(R.id.home_mydocuments_btn);
		home_integrated_query_btn = (Button) findViewById(R.id.home_integrated_query_btn);
		home_mymailbox_btn = (Button) findViewById(R.id.home_mymailbox_btn);
		//设置监听事件
		home_todo_btn.setOnClickListener(this);
		home_document_management_btn.setOnClickListener(this);
		home_business_trip_btn.setOnClickListener(this);
		home_notice_btn.setOnClickListener(this);
		home_online_addressbook_btn.setOnClickListener(this);
		home_conference_management_btn.setOnClickListener(this);
		home_leadership_agenda_btn.setOnClickListener(this);
		home_mydocuments_btn.setOnClickListener(this);
		home_integrated_query_btn.setOnClickListener(this);
		home_mymailbox_btn.setOnClickListener(this);
	}
	@Override
	public void onCallbackFromThread(ResultData resultData) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.logout_tet_view://注销用户
			SharePreferencesUtil.clearLoginUserName(this);
			//跳转至login页面
			Intent intent = new Intent();
			intent.setClass(this, LoginActivity.class);
			startActivity(intent);
			finish();
			break;
		case R.id.home_business_trip_btn://出差申请
			intent = new Intent();
			intent.setClass(this, BusinessTripListActivity.class);
			startActivity(intent);
			break;
		case R.id.home_todo_btn://代办事宜
			intent = new Intent();
			intent.setClass(this, ToDoThingActivity.class);
			startActivity(intent);
			break;
		case R.id.home_document_management_btn://公文管理
			intent = new Intent();
			intent.setClass(this, DocumentManagementActivity.class);
			startActivity(intent);
			break;
		case R.id.home_notice_btn://通知公告
			intent = new Intent();
			intent.setClass(this, NoticeListActivity.class);
			startActivity(intent);
			break;
		case R.id.home_online_addressbook_btn://在线通讯录
			intent = new Intent();
			intent.setClass(this, OnlineAddressBookActivity.class);
			startActivity(intent);
			break;
		case R.id.home_conference_management_btn://会议管理
			intent = new Intent();
			intent.setClass(this, ConferenceManagementActivity.class);
			startActivity(intent);
			break;
		case R.id.home_leadership_agenda_btn://领导日程
			intent = new Intent();
			intent.setClass(this, LeaderShipAgendaActivity.class);
			startActivity(intent);
			break;
		case R.id.home_mydocuments_btn://我的文档
			break;
		case R.id.home_integrated_query_btn://综合查询
			break;
		case R.id.home_mymailbox_btn://我的邮箱
			break;
		default:
			break;
		}
		
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		if(keyCode == KeyEvent.KEYCODE_BACK){
			ExitUtil.openDialog(this);
			return false;
		}
		return true;
	}
}
